package com.yunsom.testdemo.socket;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @author Xbao
 * @description
 * @date 2022/5/27 15:17
 */
public class ClientBSocketTest {


  public static void main(String[] args) {

    try {

      Socket socket = new Socket("127.0.0.1", 9999);

      BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

      BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));

      while (true){
        String str = bufferedReader.readLine();

        bufferedWriter.write(str);
        bufferedWriter.write("\n");
        bufferedWriter.flush();
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

  }

}
